<?php
	function ThongBaoLoi($thongbao = "")
	{
		echo "<h3>Lỗi</h3><p class='ThongBaoLoi'>$thongbao</p>";
	}
	
	function ThongBao($thongbao = "")
	{
		echo "<h3>Hoàn thành</h3><p class='ThongBao'>$thongbao</p>";
	}
	
	function KiemTraNgay(&$chuoingay)
	{
		// Input: 22/02/2013
		$arr = explode("/", $chuoingay);
		
		$ngay = (int)$arr[0];
		$thang = (int)$arr[1];
		$nam = (int)$arr[2];
		
		if(checkdate($thang, $ngay, $nam))
		{
			// Output: 2013-02-22
			$chuoingay = "$nam-$thang-$ngay";
			
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function InNgay($chuoingay)
	{
		// Input: 22/02/2013
		$arr = explode("-", $chuoingay);
		
		$nam = $arr[0];
		$thang = $arr[1];
		$A = $arr[2];
		
		$arr1 = explode(" ", $A);
		$ngay = $arr1[0];
		$time = $arr1[1];
		
		$datetime = $ngay . "/" . $thang . "/" . $nam . ", " . $time;
		
		return $datetime;
	}
	
	function PhanTrang($totalrows = 0, $start = 0, $limit = 10, $link = "")
	{
		if($totalrows > $limit)
		{
			echo "<ul class='PhanTrang'>";
			
			if($start > 0)
			{
				echo "<li class='arrowleft'><a href='" . $link . ($start - $limit) . "'>&nbsp;</a></li>";
			}
			
			$page = 1;
			for($i = 0; $i < $totalrows; $i = $i + $limit)
			{
				if($i == $start) echo "<li class='active'><a href='" . $link . $i . "'>{$page}</a></li>";
				else echo "<li><a href='" . $link . $i . "'>{$page}</a></li>";
				$page++;
			}
			
			if($start < $totalrows - $limit)
			{
				echo "<li class='arrowright'><a href='" . $link . ($start + $limit) . "'>&nbsp;</a></li>";
			}
			
			echo "</ul>";
		}
	}
	
	function unlinkimg($img)
	{
		$url = $img;
		return unlink($url);
	}

	function DTBMH_HK($diem1,$diem2,$diem3)
	{
		return ($diem1+($diem2*2)+($diem3*3))/(float)6;
	}
	function DTBMH_CN($diemTB1,$diemTB2)
	{
		return ($diemTB1+($diemTB2*2))/(float)3;
	}
	
	function LoaiGioi($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 6.5)
			{
				$kt = false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiKha($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 5)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiTB($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 3.5)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	
	function LoaiYeu($MaHocSinh, $NamHoc, $HocKy)
	{
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		$kt = true;
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['DTB_HK'] < 2)
			{
				$kt =false;
				break;
			}
		}
		return $kt;
	}
	function XetHanhKiem($HanhKiem1,$HanhKiem2)
	{
		return ($HanhKiem1+$HanhKiem2+1)/2;
	}
	function DTB_HK($MaHocSinh, $NamHoc, $HocKy)
	{
		$tu =0; $mau = 0;
		$diemhk = new diemhkbs();
		$diemhk->MaHocSinh = $MaHocSinh;
		$diemhk->HocKy = $HocKy;
		$diemhk->NamHoc = $NamHoc;
		$ds = $diemhk->GetList();
		$dem = ($ds == false ? 0 : count($ds));
		for($i = 0; $i < $dem; $i++)
		{
			if($ds[$i]['ThiLai'] == 0)
				$tu+=($ds[$i]['DTB_HK']*$ds[$i]['HeSo']);
			else
			{
				$diemthilai = new diemthilaibs();
				$diemthilai->MaHocSinh = $ds[$i]['MaHocSinh'];
				$diemthilai->HocKy = $ds[$i]['HocKy'];
				$diemthilai->NamHoc = $ds[$i]['NamHoc'];
				$diemthilai->MaMonHoc = $ds[$i]['MaMonHoc'];
				$dsthilai = $diemthilai->GetList();
				$tu+=($dsthilai[0]['DiemTB']*$ds[$i]['HeSo']);
			}
			$mau+=$ds[$i]['HeSo'];
		}
		return $tu/(float)$mau;
	}
?>